package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.CustomerDao;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author dyqstart
 * @create 2021-09-03-17:22
 * @since 1.0.0
 */
@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    CustomerDao customerDao;

    @Override
    public Map<String, Object> getCustomerList(Integer page, Integer rows, String customerName) {
        Integer total = customerDao.getCount();
        List<Customer> list = customerDao.getCustomerList(page,rows,customerName);

        HashMap<String, Object> map = new HashMap<>();
        map.put("total",total);
        map.put("rows",list);
        return map;
    }

    @Override
    public void saveOrUpdateByCustomerId(Customer customer, Integer customerId) {
        if (customerId == null){
            //添加客户
            customerDao.saveCustomer(customer);
        }else {
            //修改客户
            customerDao.updateCustomer(customer,customerId);
        }
    }

    @Override
    public void deleteCustomerByIds(String ids) {
        String[] split = ids.split(",");
        customerDao.deleteCustomerById(split);
    }
}
